import axios from 'axios';
import config from './config';
import {
  API
} from '../config/api';
//console.log(config)
export const httpGet = (url, params = {}, options) => {

  const [key1, key2] = url.split('/');
  return axios({
    url: API[key1][key2],
    method: 'GET',
    params,
    ...options,
  });
}

export const httpPost = (url) => {
  return axios();
}

axios.defaults.headers['Content-Type'] = 'application/json';
axios.defaults.baseURL = config.baseURL;
axios.defaults.timeout = 20000;
// axios.defaults.transformRequest = params => {
//   return JSON.stringify(params);
// }

axios.interceptors.request.use(config => {
 //console.log(config);
   //config.params['name'] = 890889;
  //   加载中。。。
  //alert('加载中')
  return config;
}, err => Promise.reject(err));

axios.interceptors.response.use(response => {
//console.log(response);
  switch (response) {
    // default:

    //   break;
  }
  //   拿到数据
  return response;
}, err => Promise.reject(err));
